<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>

			<%@ include file="/include/gnb.jsp"%>
			<!-- Main Start -->
			<div id="maincontainer">
				<!-- LeftMenu Start -->
				<div id="leftmenu">
					<%@ include file="/include/lnb.jsp"%>
				</div>
				<!-- Contants Start -->
				<div id="contants">
					<div class="height_10p"></div>
					<form id="commonForm" name="commonForm" method="post">
						<input type="hidden" id="_groupId" name="_groupId" value="${_groupId}" />
						<input type="hidden" id="_menuId" name="_menuId" value="${_menuId}" />
						<input type="hidden" id="_menuType" name="_menuType" value="${_menuType}" />
						<input type="hidden" id="_menuNm" name="_menuNm" value="${_menuNm}" />
						<input type="hidden" id="_menuAuth" name="_menuAuth" value="${_menuAuth}" />
						<input type="hidden" id="_prevUpCode" name="_prevUpCode" value="${_prevUpCode}" />
						<input type="hidden" id="_prevCode" name="_prevCode" value="${_prevCode}" />
						<input type="hidden" id="_startRowNo" name="_startRowNo" value="${_startRowNo}" />
						<input type="hidden" id="_pageSize" name="_pageSize" value="12" />
						<input type="hidden" id="_delYn" name="_delYn" value="N" />
					</form>
					<div id="ajaxDivList" class="noborder"></div>
				</div>
				<!-- Contants End -->
			</div>
		</div>
		<!-- Footer Start -->
		<div id="footer">
			<%@ include file="/include/footer.jsp"%>
		</div>
	</div>

<script>
var url = "boardPhotoMgmt.action";
var params = "target=bmList";
var targetElement = "ajaxDivList";

var pmModule = {
		loadList: function() {
			var rParams = params + "&" + $("#commonForm").serialize() + ($("#loadCheck").val() == "OK" ? ($("#isNew").val() == "Y" ? "&searchVal1=" + $("#searchVal1").val() : "&" + $("#searchForm").serialize()) : "");

			this.makeList(url, rParams);
		},
		
		setBinding: function() {
			var that = this;
			
			$("#searchVal1").keypress(function(e) {
				if (e.keyCode == "13") {
					return false;
				}
			});
			
			$("#searchBtn").bind({
				click: function(e) {
					that.loadList();
				}
			});
		},
		
		setUnbinding: function() {
			$("#searchVal1").unbind();
			$("#searchBtn").unbind();
		},

		setAdd: function() {
			$("#_prevCode").val("");
			
			var rParams = "target=bmAdd&" + $("#commonForm").serialize() + "&" + $("#searchForm").serialize();
			
			this.makeList(url, rParams);
		},
		
		selectCategory: function(categoryType, categoryId) {
			var secondLength = $("#categorySecond option").length;
			var thirdLength = $("#categoryThird option").length;
			
			if (categoryType == "1") {
				$("#categorySecond").val("");
				$("#categoryThird").val("");
			} else if (categoryType == "2") {
				for (var i = 0; i < secondLength; i++) {
					if ($("#categorySecond option").eq(i).val() == categoryId) {
						$("#categoryFirst").val(	$("#categorySecond option").eq(i).attr("first"));
					}
				}
				$("#categoryThird").val("");
			} else {
				for (var i = 0; i < thirdLength; i++) {
					if ($("#categoryThird option").eq(i).val() == categoryId) {
						$("#categoryFirst").val(	$("#categoryThird option").eq(i).attr("first"));
						$("#categorySecond").val(	$("#categoryThird option").eq(i).attr("second"));
					}
				}
			}
			$("#categoryId").val(categoryId);
		},
		
		setFileAdd: function(that) {
			var fileCount = $("input[type=file]").length;
			var strHtml = "<tr>"
							+ "<th>첨부 파일 #" + (fileCount + 1) + "</th>"
							+ "<td>"
							+ "<input type=\"file\" id=\"boardFile" + (fileCount + 1) + "\" name=\"boardFile" + (fileCount + 1) + "\" class=\"input_text\" />"
							+ "</td>"
							+ "</tr>";
							
			$(that).parent().parent().parent().append(strHtml);
		},
		
		getDetail: function(userId, delYn) {
			$("#_prevCode").val(userId);
			$("#_delYn").val(delYn);
			
			var rParams = "target=bmDetail&" + $("#commonForm").serialize() + ($("#loadCheck").val() == "OK" ? "&" + $("#searchForm").serialize() : "");

			this.makeList(url, rParams);
		},

		setDelete: function() {
			if (!confirm("해당 항목을 " + ($("#_delYn").val() == "Y" ? "완전 " : "") + "삭제합니다. 계속 하시겠습니까?")) {
				return;
			}
			
			var rParams = "target=" + ($("#_delYn").val() == "Y" ? "bmDeleteFinal" : "bmDelete") + "&" + $("#commonForm").serialize() + "&" + $("#searchForm").serialize();

			this.makeList(url, rParams);
		},

		setModify: function() {
			$("#searchForm").find("input[type=text]").removeAttr("disabled");
			$("#searchForm").find("input[type=password]").removeAttr("disabled");
			$("#searchForm").find("input[type=radio]").removeAttr("disabled");
			$("#searchForm").find("input[type=file]").show();
			$("#searchForm").find("select").removeAttr("disabled");
			$("#searchForm").find("textarea").removeAttr("disabled");
			$(".fileDiv").hide();
			$(".btnModify").hide();
			$(".btnSave").show();
			$("#searchForm").append("<input type=\"hidden\" id=\"_groupId\" name=\"_groupId\" value=\"" + $("#_groupId").val() + "\" />");
			$("#searchForm").append("<input type=\"hidden\" id=\"_menuId\" name=\"_menuId\" value=\"" + $("#_menuId").val() + "\" />");
			$("#searchForm").append("<input type=\"hidden\" id=\"_menuType\" name=\"_menuType\" value=\"" + $("#_menuType").val() + "\" />");
			$("#searchForm").append("<input type=\"hidden\" id=\"_menuNm\" name=\"_menuNm\" value=\"" + $("#_menuNm").val() + "\" />");
			$("#searchForm").append("<input type=\"hidden\" id=\"_menuAuth\" name=\"_menuAuth\" value=\"" + $("#_menuAuth").val() + "\" />");
			$("#searchForm").append("<input type=\"hidden\" id=\"_prevUpCode\" name=\"_prevUpCode\" value=\"" + $("#_prevUpCode").val() + "\" />");
			$("#searchForm").append("<input type=\"hidden\" id=\"_prevCode\" name=\"_prevCode\" value=\"" + $("#_prevCode").val() + "\" />");
			$("#searchForm").append("<input type=\"hidden\" id=\"_startRowNo\" name=\"_startRowNo\" value=\"" + $("#_startRowNo").val() + "\" />");
			$("#searchForm").append("<input type=\"hidden\" id=\"_pageSize\" name=\"_pageSize\" value=\"" + $("#_pageSize").val() + "\" />");
		},
		
		save: function() {
			var boardNm = $("#boardNm");
			if (boardNm.val() == "") {
				alert("제목을 입력하여 주십시오.");
				boardNm.focus();
				return;
			}
			
			var categoryId = $("#categoryId");
			if ($("#categoryFirst").length > 0 && categoryId.val() == "") {
				alert("카테고리를 선택하여 주십시오.");
				categoryId.focus();
				return;
			}

			var boardDesc = $("#boardDesc");
			if (boardDesc.val() == "") {
				alert("내용을 입력하여 주십시오.");
				boardDesc.focus();
				return;
			}

			var isFileCheck = "";
			var fileCount = $("input[type=file]").length;
			for (var i = 1; i <= fileCount; i++) {
				if ($("#boardFile" + i).val() != "") {
					isFileCheck = isFileCheck + (i == 1 ? "" : "|") + "1";
				} else {
					isFileCheck = isFileCheck + (i == 1 ? "" : "|") + "0";
				}
			}
			$("#isFileCheck").val(isFileCheck);
			
			if (!confirm("해당 항목을 저장합니다. 계속 하시겠습니까?")) {
				return;
			}

			$("#searchForm").attr("action","boardPhotoAdd.action");
			$("#searchForm").attr("target","formProcess");
			$("#searchForm").submit();
			
			this.complete();
		},
		
		complete: function() {
			$("#searchForm").find("input[type=text]").attr("disabled","disabled");
			$("#searchForm").find("input[type=password]").attr("disabled","disabled");
			$("#searchForm").find("input[type=radio]").attr("disabled","disabled");
			$("#searchForm").find("input[type=file]").hide();
			$("#searchForm").find("select").attr("disabled","disabled");
			$("#searchForm").find("textarea").attr("disabled","disabled");
			$(".fileDiv").show();
			$(".btnModify").show();
			$(".btnSave").hide();
			$("#searchForm > #_groupId").remove();
			$("#searchForm > #_menuId").remove();
			$("#searchForm > #_menuType").remove();
			$("#searchForm > #_menuNm").remove();
			$("#searchForm > #_menuAuth").remove();
			$("#searchForm > #_prevUpCode").remove();
			$("#searchForm > #_prevCode").remove();
			$("#searchForm > #_startRowNo").remove();
			$("#searchForm > #_pageSize").remove();
		},

		reset: function(cmd) {
			$("#searchForm").each(function(){
				this.reset();
			});

			if (cmd == "reset") {
				this.complete();
			}
		},

		getList: function(cmd) {
			if (cmd == "reset") {
				this.reset(cmd);
			}
			this.loadList();
		},
		   
		makeList: function(sUrl, sParams) {
			var that = this;
			
			$.ajax({
				url : sUrl,
				type : "POST",
				data : sParams,
				dataType : "html",
				success : function(data){
					$("#" + targetElement).html(data);

					that.setUnbinding();
					that.setBinding();
					that.initPage();
					sortTable();
					
					if ($("#nodata").html() != null) {
						if ($("#_startRowNo").val() != "0") {
							$("#_startRowNo").val("0");
							loadList();
						} else {
							$("#nodata").css({"height":(parseInt($("#formlist1").css("height").replace("px","")) - 10)});
						}
					}
				}
			});
		},
		
		initPage: function(){
			this.initPageSize();
		},
		     
		initPageSize: function(){
			var msg = "";
			
			// warp
			var valueGwpw = getObjectValue("#warp", "width"); 
			var gwpw = (valueGwpw == null) ? 0 : valueGwpw; // 대상 전체 폭
			var valueGwph = getObjectValue("#warp", "height"); 
			var gwph = (valueGwph == null) ? 0 : valueGwph; // 대상 전체 높이
			msg = appendMessage(msg, "#warp");
			
			setObjectValue("#container", "width", Math.round(gwpw - 40));
			
			// container
			var valueGcw = getObjectValue("#container", "width"); 
			var gcw = (valueGcw == null) ? 0 : valueGcw; // 대상 전체 폭
			var valueGch = getObjectValue("#container", "height"); 
			var gch = (valueGch == null) ? 0 : valueGch; // 대상 전체 높이
			msg = appendMessage(msg, "#container");
			
			// contants
			setObjectValue("#contants", "width", Math.round(gcw - 180 - 10));
			msg = appendMessage(msg, "#contants");
			
			// formtitle
			var valueGftw = getObjectValue("#formtitle", "width");
			var gftw = (valueGftw == null) ? 0 : valueGftw; // 대상 전체 폭
			var valueGfth = getObjectValue("#formtitle", "height"); 
			var gfth = (valueGfth == null) ? 0 : valueGfth; // 대상 전체 높이
			
			// formlist
			var valueGccw = getObjectValue("#contants", "width"); 
			var gccw = (valueGccw == null) ? 0 : valueGccw; // 대상 전체 폭
			var valueGcch = getObjectValue("#contants", "height"); 
			var gcch = (valueGcch == null) ? 0 : valueGcch; // 대상 전체 높이
			
			setObjectValue("#formlist1", "width", Math.round(gccw));
			setObjectValue("#formlist1", "height", Math.round(gcch - gfth - 60));
			msg = appendMessage(msg, "#formlist1");
			
			$(".LoggingMessage").html(msg);     
		}
};

$(document).ready(function(){
	pmModule.loadList();
	pmModule.initPage();
});

$(window).resize(function(){
	pmModule.initPage();
});
</script>
</body>
</html>
